package com.log4jviewer.ui.views;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;

/**
 * Class represents a handler for 'Clear errors' button. It removes all errors from Log4j-viewer Error view.
 * 
 * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
 */
public class ClearErrorsAction implements IViewActionDelegate {

    private ErrorView errorView;

    @Override
    public void run(final IAction action) {
        if (errorView.getErrorManager() != null) {
            errorView.getErrorManager().removeAllErrors();
            errorView.clearErrorTable();
        }
    }

    @Override
    public void selectionChanged(final IAction action, final ISelection selection) {
        // no code
    }

    @Override
    public void init(final IViewPart view) {
        errorView = (ErrorView) view;
    }
}
